<?php

/**
 * Description of DbLaag
 *
 * @author Nick Swartelé
 */

require_once FILE_DB_DATABASE;

class DbLaag extends Database{
    
    //Attributen
    private $id = '';
    private $parent_id = '';
    private $beschrijving = '';
    private $change_id = '';
    
    public function __construct(){
        parent::__construct();
       
    }
     
/*     Save Functie
 *     Voegt een nieuw bedrijfsonderdeel toe aan de database.
 */
      public function save ($parent_id, $beschrijving, $change_id) {          
  
        if (
             
            !empty ($parent_id) && 
            !empty ($beschrijving) &&
            !empty ($change_id)
               
            ){
           
            $query = "INSERT INTO `cofely`.`laag`(`parent_id`, `beschrijving`, `change_id`)
                        VALUES (                        
                            '" . mysql_real_escape_string($parent_id) . "',
                            '" . mysql_real_escape_string($beschrijving) . "',
                            '" . mysql_real_escape_string($change_id) . "'       
                            )";
                     
            if (DEBUG_LVL & DEBUG_LVL_QUERY)  echo __FILE__ . ' ' . __LINE__ .': ' .$query . '<br />';
            
            if (!$this->dbquery($query)){
 
               throw new Exception(DB_ERROR_NIETVERWERKT);
            }
            
            // Update Class Attributes
            $this->parent_id = $parent_id;
            $this->beschrijving = $beschrijving;
            $this->change_id = $change_id;
                  
            return TRUE;
        }
        else {
          throw new Exception(DB_ERROR_INVOERFOUT);
        }
    }
 
     public function update ($id, $parent_id, $beschrijving, $change_id){
           
        if (!empty ($id) &&
            !empty ($parent_id) &&
            !empty ($beschrijving) &&
            !empty ($change_id)){
            
            $query = "UPDATE laag
                        SET parent_id =                  '" . mysql_real_escape_string($laag_id) . "', 
                            beschrijving =               '" . mysql_real_escape_string($beschrijving) . "', 
                            change_id =                  '" . mysql_real_escape_string($change_id) . "', 
                            locatie =                    s'" . mysql_real_escape_string($locatie) . "'
                                
                        WHERE laag . id ='" . mysql_real_escape_string($id) . "'";
       
                  if (DEBUG_LVL & DEBUG_LVL_QUERY)  echo __FILE__ . ' ' . __LINE__ .': ' .$query . '<br />';
            
            if (!$this->dbquery($query)){
                    throw new Exception(DB_ERROR_NIETVERWERKT);
            }
        
            // Update Class Attributes
            $this->parent_id = $parent_id;
            $this->beschrijving = $beschrijving;
            $this->change_id = $change_id;
            
            return TRUE;
        }
        else {
             throw new Exception(DB_ERROR_INVOERFOUT);
        }
    }
    
         public function selectAll(){
         
         if($this->dbquery("SELECT * FROM `laag`")) {
            
             // Controle of er iets gevonden is in de database
             if($this->dbNumRows() >= 1){
                       return $this->dbFetchAll();  
                  
             } else {           
                 return FALSE;
             }    
                   
         } else {
             throw new Exception (DB_ERROR_COULDNOTSELECT);
         }
          
          if (DEBUG_LVL & DEBUG_LVL_QUERY)  echo __FILE__ . ' ' . __LINE__ .': ' .$query . '<br />';      
        $this->reset();
    }
    
           public function selectOne(){
         
         if($this->dbquery("SELECT * FROM `laag` WHERE `id` = '$id'")) {
            
             // Controle of er iets gevonden is in de database
             if($this->dbNumRows() >= 1){
                       return $this->dbFetchAll();  
                  
             } else {           
                 return FALSE;
             }    
                   
         } else {
             throw new Exception (DB_ERROR_COULDNOTSELECT);
         }
          
          if (DEBUG_LVL & DEBUG_LVL_QUERY)  echo __FILE__ . ' ' . __LINE__ .': ' .$query . '<br />';      
        $this->reset();
    }
    
          public function delete($id) {          
  
        if (
             
            !empty ($id)

            ){
           
            $query = "DELETE FROM `cofely`.`laag` WHERE `laag`.`id` = '$id';";
                     
            if (DEBUG_LVL & DEBUG_LVL_QUERY)  echo __FILE__ . ' ' . __LINE__ .': ' .$query . '<br />';
            
            if (!$this->dbquery($query)){
 
               throw new Exception(DB_ERROR_NIETVERWERKT);
            }
            
            // Update Class Attributes
            $this->id = $id;      
            return TRUE;
        }
        else {
          throw new Exception(DB_ERROR_INVOERFOUT);
        }
    }
    
   
    
}

?>
